# devtools::install_git('https://git.oschina.net/seifer_earth/house_price.git')
library(house.price)
library(dplyr)
# con<-connectDB()
tabln.vec<-loadData(city_code = city_code,con=con,apply.patch = F)
# extent for current city
library(raster)
ha_info.sp<-tabln.vec$ha_info.sp
extent.city<-ha_info.sp%>%
    spTransform(CRSobj = '+init=epsg:3857')%>%extent
extent.city@xmin<-extent.city@xmin-5e4
extent.city@xmax<-extent.city@xmax+5e4
extent.city@ymin<-extent.city@ymin-5e4
extent.city@ymax<-extent.city@ymax+5e4
library(stringr)
# extract all poi spatial dataframe
which.poi.sp<-str_detect(names(tabln.vec),pattern = '\\.poi\\.sp')
poi.sp.names<-names(tabln.vec)[which.poi.sp]
# get all POI density
poi.dens<-sapply(X = poi.sp.names, getDensity
                 ,list=tabln.vec,resto=200,extent.ras=extent.city)
#extract value from raster(density surface) to points(ha_info.sp)
poi.dens.pts<-sapply(poi.dens,extract,y=ha_info.sp,sp=F)
colnames(poi.dens.pts)<-paste0(colnames(poi.dens.pts),'_dens')
# compute shannon's index of POI
ha_poi.sp<-tabln.vec$ha_poi.sp
poi.diversity<-
    diversity_shannon(ha_poi.sp,poi_type ='ha_cl_name_child',
                      extent.ras =extent.city )
#extract value from raster(diversity surface ) to points(ha_info.sp)
poi.diversity.pts<-extract(x = poi.diversity,y=ha_info.sp,sp=F)
# get all POI mindist with parallel computation
poi.mindist<-sapply(X = poi.sp.names, getMindist,ha=ha_info.sp,list=tabln.vec)
colnames(poi.mindist)<-paste0(colnames(poi.mindist),'_mindist')
ha_info.sp@data<-cbind(ha_info.sp@data,
                       poi.dens.pts,
                       poi.diversity.pts,
                       poi.mindist)%>%as.data.frame
